package com.lagou.rpc.utils;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * 获取Zk操作的客户端
 */
public class GetZkClient {

    public static final String path = "/lg-rpc";

    public static CuratorFramework getZkClient() {
        RetryPolicy exponentialBackoffRetry = new ExponentialBackoffRetry(1000, 3); // 用接口接收返回值
        CuratorFramework client = CuratorFrameworkFactory.builder()
                .connectString("192.168.1.12:2181")
                .sessionTimeoutMs(50000)
                .connectionTimeoutMs(30000)
                .retryPolicy(exponentialBackoffRetry)
                .namespace("base")  // 设置了独立的命名该空间
                .build();
        client.start();
        System.out.println("连接成功");
        return client;
    }

}
